package edu.cmsc611.textsimulator;

import java.util.Arrays;

public class Registers {
	private static Registers instance=null;
	private int R[]=new int[32];
	private int F[]=new int[32];
	boolean Rbusy[]=new boolean[32];
	boolean Fbusy[]=new boolean[32];
	/**
	 * 
	 * @author Mahbubur
	 * 
	 */
	public enum registerMode{Read,Write,Idle};
	private registerMode RMode[]=new registerMode[32];


	public void setFMode(registerMode[] fMode) {
		FMode = fMode;
	}

	private registerMode FMode[]=new registerMode[32];

	Registers(){
		for(int i=0;i<Rbusy.length;i++)
			Rbusy[i]=false;
		for(int i=0;i<Fbusy.length;i++)
			Fbusy[i]=false;
		for(int i=0;i<RMode.length;i++)
			RMode[i]=registerMode.Idle;
		for(int i=0;i<FMode.length;i++)
			FMode[i]=registerMode.Idle;
	}


	public registerMode[] getRMode() {
		return RMode;
	}

	public void setRMode(registerMode[] rMode) {
		RMode = rMode;
	}

	public registerMode[] getFMode() {
		return FMode;
	}
	void printRegisterR(){
		System.out.println(Arrays.toString(R));
	}
	void printRegisterF(){
		System.out.println(Arrays.toString(F));
	}
	void setWritetoRegisterR(int index,int value)
	{
		R[index]=value;
	}
	public void setRMode(int index,registerMode value)
	{
		RMode[index]=value;
	}
	public void setFMode(int index,registerMode value)
	{
		FMode[index]=value;
	}
	public registerMode getRMode(int index)
	{
		return RMode[index];
	}
	public registerMode getFMode(int index)
	{
		return FMode[index];
	}
	void setWritetoRegisterF(int index,int value)
	{
		F[index]=value;
	}
	int readRegisterR(int index)
	{
		return R[index];
	}
	int readRegisterF(int index)
	{
		return F[index];
	}
	void setIsRegisterBusyR(int index,boolean busy){
		Rbusy[index]=busy;
	}
	void setIsRegisterBusyF(int index,boolean busy){
		Fbusy[index]=busy;
	}
	boolean isRegisterBusyR(int index){return Rbusy[index];}

	boolean isRegisterBusyF(int index){return Fbusy[index];}

	public static Registers getInstance(){
		if(instance==null){
			instance=new Registers();
		}
		return instance;
	}
}
